rm(list=ls(all=TRUE))
library(sf)
library(openxlsx)
library(readstata13)
library(tidyverse)
library(gridExtra)
library(grid)
library(RColorBrewer)
setwd(dirname(rstudioapi::getSourceEditorContext()$path))

world <- st_read("worldmap")
world <- world[!world$country2=="Antarctica",]

data0<-read_csv("data_covid_data_01012021.csv")
worlddata <- left_join(world, data0, by = c("adm0_a3_us"="ccodealp"))

worlddata$death0 <- gtools::quantcut(worlddata$total_deaths_per_million, q=5,
                                     labels=c("0-20%","20-40%","40-60%","60-80%","80-100%"))

colourPalette <- rev(brewer.pal(7,'Greys'))

colourPalette <-c("#BDBDBD", "#969696", "#737373", "#525252", "#252525")

ppi <- 600
png("Figure_1.png",width=10*ppi, height=6*ppi, res=ppi)

ggplot() +
  geom_sf(data = worlddata,aes(fill = death0),colour = "black",size=0.1,alpha=0.7)+
  labs(x=NULL, y=NULL)+
  coord_sf(crs = 4326)+
  scale_fill_manual(name="",values=colourPalette, na.value = "white")+
  guides(fill = guide_legend(nrow = 1))+
  theme(legend.position="bottom",
        panel.grid = element_blank(),
        panel.background = element_rect(fill = "white"),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank(),
        plot.title = element_text(size = 12, hjust = 0.5),
        plot.margin = margin(t = 0,r = 0,b = 0,l = 0))

dev.off()